package cn.yunbamboos.rest.service.logs.event;

import cn.yunbamboos.rest.service.logs.ILogMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;

import java.time.LocalDateTime;

public class LogEvent extends ApplicationEvent implements ILogMetadata {

    private static final Logger logger = LoggerFactory.getLogger(LogEvent.class);

    private ILogMetadata delegate;

    public LogEvent(Object source) {
        super(source);
    }

    public void setDelegate(ILogMetadata delegate) {
        this.delegate = delegate;
    }

    public void log() {
        // 输出服务调用日志
        if (logger.isDebugEnabled()) {
            logger.debug("request details {}", delegate);
        }
    }

    public String getTraceId() {
        return delegate.getTraceId();
    }

    public String getLoginTraceId() {
        return delegate.getLoginTraceId();
    }

    public long getUserId() {
        return delegate.getUserId();
    }

    public String getClientIp() {
        return delegate.getClientIp();
    }

    public String getBrowser() {
        return delegate.getBrowser();
    }

    public String getServiceName() {
        return delegate.getServiceName();
    }

    public String getServicePath() {
        return delegate.getServicePath();
    }

    public String getRealUrl() {
        return delegate.getRealUrl();
    }

    public LocalDateTime getStartTime() {
        return delegate.getStartTime();
    }

    public long getTime() {
        return delegate.getTime();
    }

    public int getCode() {
        return delegate.getCode();
    }

    public String getMsg() {
        return delegate.getMsg();
    }

    public String getIn() {
        return delegate.getIn();
    }

    public String getOut() {
        return delegate.getOut();
    }

    public boolean getAttributeForBoolean(String key){
        return delegate.getAttributeForBoolean(key);
    }

    public <T> T getAttributeForObject(String key, Class<T> clazz){
        return delegate.getAttributeForObject(key, clazz);
    }
}
